<{include file="Public:header" /}>
<div id="page-wrapper">
	<div class="row">
		<div class="col-lg-12">
			<h1 class="page-header" style="margin-top: 0px;"></h1>
		</div>
		<!-- /.col-lg-12 -->
	</div>
	<div class="row">
		<div class="col-lg-12">
			<div class="panel panel-default">
				<div class="panel-heading">
					<b>楼层管理</b>
				</div>
				<!-- /.panel-heading -->
				<div class="panel-body">
					<div class="dataTable_wrapper">
						<div id="dataTables-example_wrapper"
							class="dataTables_wrapper form-inline dt-bootstrap no-footer">
							<div class="row">
								<div class="col-sm-8">
									<form action="<{:Url('Place/floor')}>" method="get">
										<div class="dataTables_filter" style="float: left;">
											<label>楼层名称: <input type="search" name="name"
												class="form-control input-sm" placeholder="">
											</label> <select name="campus_id" id="campus_id" class="required">
												<option value="">请选择广场</option> <{volist name='squarelist'
												id='vo' }>
												<option value="<{$vo.id}>">
															<{$vo.campus_name}>
														</option> <{/volist}>
											</select>
											<button class='btn btn-primary'>查询</button>

										</div>
									</form>
									<button class='btn btn-success'
										style="float: left; margin-left: 6px" onclick="addFloor()">添加楼层</button>
								</div>
							</div>
							<div class="row">
								<div class="col-sm-12">
									<table id="yao_table"
										class="table table-striped table-bordered table-hover dataTable no-footer">
										<thead>
											<tr role="row">
												<th style="text-align: center;">所属城市</th>
												<th style="text-align: center;">广场名称</th>
												<th style="text-align: center;">建筑名称</th>
												<th style="text-align: center;">楼层名称</th>
												<th style="text-align: center;">地图放大倍数</th>
												<th style="text-align: center;">ap数量</th>
												<th style="text-align: center;">地图是否上传</th>
												<th style="text-align: center;">操作</th>

											</tr>
										</thead>
										<tbody>
											<{volist name="floorlist" id='vo' }>
											<tr class="gradeA odd" role="row">
												<td><{$vo.location_name}></td>
												<td><{$vo.campus_name}></td>
												<td><{$vo.building_name}></td>
												<td><{$vo.floor_name}></td>
												<td><{$vo.magnification}></td>
												<td><{notempty name="vo.cnt" }> <{$vo.cnt}> <{else /}>0
													<{/notempty}></td>
												<td><{empty name="vo['floor_img_path']" }><span
													style="color: red;">未上传</span> <{else/}><span
													style="color: green;">已上传</span> <{/empty}>
												</td>
												<td><a
													href="<{:Url('Apposition/position')}>?floor_id=<{$vo['id']}>">ap位置标注</a>
													| <a
													href="<{:Url('Ibeacon/position?floor_id='.$vo['id'].'&campus_id='.$vo['campus_id'])}>">Ibeacon设备</a>
													| <a
													href="<{:Url('Datepoint/region?floor_id='.$vo['id'].'&campus_id='.$vo['campus_id'])}>">指纹采集</a>
													| <a href="javascript:void(0)"
													onclick="ediFloor('<{$vo.floor_name}>','<{$vo.id}>','<{$vo.campus_id}>','<{$vo.floor_img_X}>','<{$vo.floor_img_Y}>','<{$vo.magnification}>')">编辑</a>
													| <a href="javascript:void(0)"
													onclick="deletefloor(<{$vo.id}>)"><span
														style="color: red;">删除</span>&nbsp;|</a> <a
													href="javascript:void(0)"
													onclick="upload('<{$vo.floor_name}>','<{$vo.building_id}>',<{$vo.id}>,<{$vo.campus_id}>)">地图上传</a>
												</td>

											</tr>
											<{/volist}>

										</tbody>
									</table>
								</div>
							</div>

							<div class="row">
								<div class="col-sm-12">
									<div class='pages'><{$page}></div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<!-- /.panel-body -->
			</div>
			<!-- /.panel -->
		</div>
		<!-- /.col-lg-12 -->
	</div>

</div>

<!-- 添加楼层信息-->
<div id="addFloor1" class="hide">
	<form class="form-horizontal">
		<div class="row">
			<div class="col-sm-12">
				<label class="col-sm-12">选择广场</label>
				<div class="col-sm-12">
					<select id="campus_ids"> <{volist name="squarelist" id="v"
						}>
						<option value="<{$v.id}>">
									<{$v.campus_name}>
								</option> <{/volist}>
					</select> <select id="building_id">

					</select>
				</div>
			</div>
			<div class="control-group span8">
				<label class="control-label" style="padding-top: 0px;">楼层名称：</label>
				<div class="controls">
					<input type="text" id="floor_name"
						class="input-normal control-text" style="height: 30px;">
				</div>
			</div>
		</div>
	</form>
</div>

<!--     <form method="post" enctype="multipart/form-data" action="__URL__/upload">
        附件：<input type="file" name="image" />
    <input type="submit" value="提交">
    </form> -->

<!-- 编辑楼层-->
<div id="ediFloor1" class="hide">
	<!--     action+"__URL__/upload" enctype="multipart/form-data" method="post" -->
	<form class="form-horizontal">
		<div class="row">
			<div class="control-group span10">
				<label class="control-label" style="padding-top: 0px; width: 140px">广场名称：</label>
				<div class="controls">
					<select id="campus_id1"> <{volist name="squarelist" id="v"
						}>
						<option value="<{$v.id}>">
									<{$v.campus_name}>
								</option> <{/volist}>
					</select>
				</div>
			</div>
			<div class="control-group span10">
				<label class="control-label" style="padding-top: 0px; width: 140px">建筑名称：</label>
				<div class="controls">
					<select id="building_id2">

					</select>
				</div>
			</div>
			<div class="control-group span8">
				<label class="control-label" style="padding-top: 0px; width: 140px">楼层名称：</label>
				<div class="controls">
					<input type="text" id="floor_name1"
						class="input-normal control-text" style="height: 30px;">
				</div>
			</div>
			<div class="control-group span8">
				<label class="control-label" style="padding-top: 0px; width: 140px">地图放大倍数：</label>
				<div class="controls">
					<input type="text" id="magnification"
						class="input-normal control-text" style="height: 30px;">
				</div>
			</div>

		</div>
	</form>
</div>
<!-- 上传图片-->
<div id="upload1" class="hide">
	<form method="post" class="form-horizontal"
		enctype="multipart/form-data" action="<{:Url('Place/upload')}>">
		<div class="row">

			<div class="control-group span8">
				<label class="control-label" style="padding-top: 0px;">楼层地图：</label>
				<div class="controls">
					<input type="hidden" id="building_id_up" name="building_id_up">
					<input type="hidden" id="floor_id_up" name="floor_id_up"> <input
						type="hidden" id="campus_id_up" name="campus_id_up"> <input
						type="file" name="image" class="input-normal control-text"
						style="height: 30px;" />
				</div>
				<input type="text" style="display: none;" name="page" id="p"
					value="<?php echo isset($_GET['page'])?$_GET['page']:1;?>" />
			</div>
			<div class="control-group span8">
				<label class="control-label" style="padding-top: 0px; width: 140px">楼层的物理宽度(厘米)：</label>
				<div class="controls">
					<input type="text" name="floorXSize" id='floorXSize'
						class="input-normal control-text" style="height: 30px;">
				</div>
			</div>
			<div class="control-group span8">
				<label class="control-label" style="padding-top: 0px; width: 140px">楼层的物理高度(厘米)：</label>
				<div class="controls">
					<input type="text" name="floorYSize" id='floorYSize'
						class="input-normal control-text" style="height: 30px;">
				</div>
			</div>
		</div>
		<input type="submit" class="button button-primary" value="提交">
	</form>
	<!-- <form method="post" enctype="multipart/form-data" action="__URL__/upload">
        附件：<input type="file" name="image" />
    <input type="submit" value="提交">
    </form> -->
</div>

<script src="__PUBLIC__/js/jquery-1.8.3.min.js" type="text/javascript">
	</script>
<script type="text/javascript">
		$(document).ready(function() {

			$("#checkedAll").click(function() {
				if($(this).prop('checked')) { // 全选 
					$("input[name='checkbox_name']").each(function() {
						$(this).prop('checked', true);
					});
				} else { // 取消全选 
					$("input[name='checkbox_name']").each(function() {
						$(this).prop('checked', false);
					});
				}
			});

		});
	</script>
<script src="__PUBLIC__/js/bui.js"></script>
<!-- 删除用户 -->
<script type="text/javascript">
		//消息消失
		function dispoint(messge) {
			BUI.Message.Show({
				msg: messge,
				icon: 'success',
				buttons: [],
				autoHide: true,
				autoHideDelay: 1000

			});
		}

		function show(hidden) {
			BUI.Message.Confirm('确认要删除？', function() {
				setTimeout(function() {
					$.ajax({
						type: 'get',
						url: "<{:Url('Place/delCommager','id=')}>" + hidden,
						success: function(msg) {
							dispoint("删除成功！");
							location.reload();
						}
					});

					//BUI.Message.Alert('这只是简单的错误信息','error');
				});

			}, 'question');
		}
	</script>
<!-- 编辑和添加用户js -->
<script type="text/javascript">
		var Overlay = BUI.Overlay;
		//添加楼层信息
		function addFloor() {
			var dialog = new Overlay.Dialog({
				title: '添加楼层信息',
				width: 450,
				height: 250,
				closeAction: 'destroy', //每次关闭dialog释放
				contentId: 'addFloor1',
				buttons: [{
					text: '保存',
					elCls: 'button button-primary',
					handler: function() {
						var campus_id = $("#campus_ids").val();
						var building_id = $('#building_id').val();
						var floor_name = $("#floor_name").val();
						//alert(building_id);return;
						$.post("<{:Url('Place/ajaxAddFloor')}>", {
							'campus_id': campus_id,
							'floor_name': floor_name,
							'building_id': building_id
						}, function(data) {
							if(data == 'ok') {
								dispoint("添加楼层信息成功");
								dialog.close();
								location.reload();
							} else {
								dispoint("添加楼层信息失败");
							}
						})
					}
				}, {
					text: '取消',
					elCls: 'button',
					handler: function() {
						this.close();
					}
				}]
			});
			dialog.show();
		}
		//修改楼层信息
		function ediFloor(f_name, id, campus_id, floor_img_X, floor_img_Y,magnification) {
			//alert(realWidth);
			var sec_id = campus_id;
			var sec_obj = $("#campus_id1");
			jsSelectIsExitItem(sec_obj, sec_id); //自定义函数
			$("#floor_name1").val(f_name);
			$("#magnification").val(magnification);
			//   $("#floor_img_Y1").val(floor_img_Y);
			var dialog = new Overlay.Dialog({
				title: '修改楼层信息',
				width: 450,
				height: 300,
				closeAction: 'destroy', //每次关闭dialog释放
				contentId: 'ediFloor1',
				buttons: [{
					text: '提交修改',
					elCls: 'button button-primary',
					handler: function() {
						//  var floor_img_X   = $("#floor_img_X1").val();
						//  var floor_img_Y  = $("#floor_img_Y1").val();
						var floor_name1 = $('#floor_name1').val();
						var building_id = $('#building_id2').val();
						var campus_id = $('#campus_id1').val();
						var floor_name = $('#floor_name1').val();
						var magnification = $("#magnification").val();
						$.post("<{:Url('Place/ajaxEdiFloor')}>", {
							'id': id,
							'campus_id': campus_id,
							'building_id': building_id,
							'floor_name': floor_name,
							'magnification' : magnification
						}, function(data) {
							if(data == 'ok') {
								dispoint("修改楼层信息成功");
								dialog.close();
								location.reload();
							} else {
								dispoint("修改楼层信息失败");
							}
						})
					}
				}, {
					text: '取消',
					elCls: 'button',
					handler: function() {
						this.close();
					}
				}]
			});
			dialog.show();
		}

		function upload(floor_name, building_id, id, campus_id) {
			$("#building_id_up").val(building_id);
			$("#floor_id_up").val(id);
			$("#campus_id_up").val(campus_id);
			var dialog = new Overlay.Dialog({
				title: '添加楼层地图',
				width: 500,
				height: 300,
				closeAction: 'destroy', //每次关闭dialog释放
				contentId: 'upload1',
				buttons: [{
					text: '取消',
					elCls: 'button',
					handler: function() {
						this.close();
					}
				}]
			});
			dialog.show();
		}

		// 1.判断select选项中 是否存在Value="paraValue"的Item  
		function jsSelectIsExitItem(objSelect, objItemValue) {
			for(var i = 0; i < objSelect[0].length; i++) {
				if(objSelect[0][i].value == objItemValue) {
					objSelect[0][i].selected = true;
					break;
				}
			}

		}

		$('#campus_ids').click(function() {
			getbuildingajax();
		})
		$('#campus_id1').click(function() {
			getbuildingajaxs();
		})
		$(function() {
			//getbuildingajax();
			getbuildingajaxs();
		})
		$(function() {
			getbuildingajax();
			//getbuildingajaxs();
		})

		function getbuildingajax() {

			$id = $('#campus_ids').val();
			//alert($id);
			$building_id = $('#building_id');
			$building_id.empty();
			$.ajax({
				type: "post",
				url: "<{:Url('Place/getbuilding')}>",
				dataType: 'json',
				data: {
					'id': $id
				},
				async: true,
				success: function(result) {
					if(result) {
						$.each(result, function(index, array) {

							var option = "<option value='" + array['id'] + "'>" + array['building_name'] + "</option>";
							$building_id.append(option);
						});
					}
				}
			});
		}
		//
		function getbuildingajaxs() {

			$id = $('#campus_id1').val();
			//alert($id);
			$building_ids = $('#building_id2');
			$building_ids.empty();
			$.ajax({
				type: "post",
				url: "<{:Url('Place/getbuildings')}>",
				dataType: 'json',
				data: {
					'id': $id
				},
				async: true,
				success: function(result) {
					if(result) {
						$.each(result, function(index, array) {

							var option = "<option value='" + array['id'] + "'>" + array['building_name'] + "</option>";
							$building_ids.append(option);
						});
					}
				}
			});
		}
		//删除楼层
		function deletefloor(id) {
			BUI.Message.Confirm('确认要删除？', function() {
				setTimeout(function() {
					$.ajax({
						type: "post",
						url: "<{:Url('Place/deletefloor')}>",
						async: true,
						data: {
							'id': id
						},
						dataType: 'json',
						success: function(re) {
							if(re) {
								dispoint("删除成功！");
								location.reload();
							}
						}
					});

					//BUI.Message.Alert('这只是简单的错误信息','error');
				});

			}, 'question');

		}
	</script>

<{include file="Public:footer" /}>
